<?php
namespace app\ home\ model;

use think\ Model;

class BfNewslist extends Model {
	protected $table = 'bf_newslist';
	protected $dateFormat = 'Y-m-d H:i:s';
	protected $type = [
        'create_time'    =>  'timestamp',
    ];

	public static function loadlist($search = []){
        $where = [];
        
        $search['lanmuid'] !== '0' ? $where[] = ['lanmuid','=',$search['lanmuid']] : null;
        
        if(empty($where)){
            $where = true;
        }
        
        $list = self :: where($where) -> order('id desc') -> paginate($search['pagesize'],false,['query' => request()->get()]);
		return $list;
	}
    
    public function getFlagAttr($v){
        $str = ['隐藏','显示','删除'];
        return $str[$v];
    }
    
    public function loadlanmu(){
		return $this->hasOne('BfNewslanmu','id','lanmuid')  -> field('id,name');
	}
    
    public function loadcover(){
		return $this->hasOne('BfAttachments','id','cover')  -> field('id,subject,path');
	}
    
}